package com.xuecheng.content.controller.api;

import com.xuecheng.base.model.RestResponse;
import com.xuecheng.content.model.dto.AddOrUpdateTeachplanDto;
import com.xuecheng.content.model.vo.TeachPlanTreeVo;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping("teachplan")
@Api(tags = "课程大纲相关接口")
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;


    @GetMapping("/{courseId}/tree-nodes")
    @ApiOperation("根据id查询课程计划")
    public List<TeachPlanTreeVo> getTeachPlan(@PathVariable Long courseId){
        return teachplanService.getTeachPlan(courseId);
    }

    @PostMapping
    @ApiOperation("新增/修改课程计划")
    public void saveOrUpdateTeachPlan(@RequestBody AddOrUpdateTeachplanDto teachplanDto){
        teachplanService.saveOrUpdateTeachPlan(teachplanDto);
    }

    @DeleteMapping("/{teachplanId}")
    @ApiOperation("根据id删除课程以及子节")
    public void deletePlan(@PathVariable Long teachplanId){

        teachplanService.deletePlan(teachplanId);

    }

    @PostMapping("/moveup/{teachplanId}")
    @ApiOperation("小节上移操作")
    public RestResponse moveUp(@PathVariable Long teachplanId){

        teachplanService.moveUp(teachplanId);
        return RestResponse.success();
    }

    @PostMapping("/movedown/{teachplanId}")
    @ApiOperation("小节上移操作")
    public RestResponse movedown(@PathVariable Long teachplanId){

        teachplanService.movedown(teachplanId);
        return RestResponse.success();
    }




}
